home *** CD-ROM | disk | FTP | other *** search
- Listing 6 - A test program for a queue of str
-
- //
- // strtst2.cpp - test strq1
- //
-
- #include <iostream.h>
-
- #include "strq2.h"
- #include "showheap.h"
-
- #define DIM(a) (sizeof(a)/sizeof(a[0]))
-
- void test()
- {
- char c;
- size_t qn;
- str qe;
- strq q[4];
- while (cin >> c)
- {
- showheap();
- if (c == 'q')
- break;
- if (c == 'a')
- {
- cin >> qn >> qe;
- if (qn >= DIM(q))
- cout << "no such queue\n";
- else
- q[qn].append(qe);
- }
- else if (c == 'c')
- {
- cin >> qn;
- if (qn >= DIM(q))
- cout << "no such queue\n";
- else
- q[qn].clear();
- }
- else if (c == 'r')
- {
- cin >> qn;
- if (qn >= DIM(q))
- cout << "no such queue\n";
- else if (q[qn].remove(qe))
- cout << "removed " << qe << '\n';
- else
- cout << "q[" << qn << "] is empty\n";
- }
- else
- continue;
- for (size_t i = 0; i < DIM(q); ++i)
- {
- cout << i << ':';
- q[i].print(cout);
- cout << '\n';
- }
- }
- }
-
- int main()
- {
- showheap();
- test();
- showheap();
- return 0;
- }
-
-
-